package leetcode_501_600;

public class LeeCode_541 {
    public static void main(String[] args) {
        System.out.println(reverseStr("abcdefg", 2));
    }
    private static String reverseStr(String s, int k) {
        char[] cs = s.toCharArray();
        int l = 0, r = l +  k - 1;
        while (l < cs.length){
            int tl = l, tr = r;
            if (tr >= cs.length){
                tr = cs.length - 1;
            }
            while (tl < tr){
                char tmp = cs[tl];
                cs[tl] = cs[tr];
                cs[tr] = tmp;
                tl++;
                tr--;
            }
            l += 2 * k;
            r += 2 * k;
        }
        return new String(cs);
    }
}
